﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace CSharpTestProject.Utils
{
    public class _Sql
    {
        SqlConnection conn;
        SqlConnection Conn
        {
            get { return conn; }
        }
        public void SqlClose()
        {
            conn.Close();
        }
        public bool SqlConnect()
        {
            string constring = "Data Source=114.55.89.13;Initial Catalog=test01; User ID=sa;Pwd=198312Bpr@7;Integrated Security=false;";
            SqlConnection conn = new SqlConnection(constring);
            try
            {
                conn.Open();
                this.conn = conn;
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        // 查询
        public DataSet SqlFind(string sql)
        {
            SqlDataAdapter reader = new SqlDataAdapter(sql, conn);
            DataSet data = new DataSet();
            reader.Fill(data);
            return data;
        }
        // 增删改
        public bool ManageData(string sql)
        {
            SqlCommand cmd = new SqlCommand(sql, conn);
            int num = cmd.ExecuteNonQuery();
            return num > 0;
        }
    }
}
